False sense of security with `snprintf_s`

Posted by xtofl on Stack Overflow See other posts from Stack Overflow or by xtofl
Published on 2010-04-29T14:46:17Z Indexed on 2010/04/29 14:57 UTC
Read the original article Hit count: 323

MSVC's "secure" sprintf funcions have a template version that 'knows' the size of the target buffer. However, this code happily paints 567890 over the stack after the end of bytes...

char bytes[5];
_snprintf_s( bytes, _TRUNCATE, "%s", "1234567890" );

Any idea what I do wrong, or is this a known bug?

(I'm working in VS2005 - didn't test in 2008 or 2010)

© Stack Overflow or respective owner

Related posts about c++

Related posts about visual-c++